﻿ <?php
/**********************************************************
** Lime Manager
** Thomas Knobloch & Clément Troesch
** Manager Ajax Tables View
***********************************************************/
?>
<?php include_once "../../model/DevelopperModel.php"; ?>
<?php include_once "../../model/SessionModel.php"; ?>
<?php include_once "../../model/DevelopperModel.php"; ?>
<?php include_once "../main/QueryTableView.php"; ?>
<?php session_start(); ?>

<div class="section_title" id="tables"><h1> Tables </h1></div>
<div class="section_info">
	Obtention des renseignements sur les tables, les caractéristiques de stockage,la liste des index associés et leurs caractéristiques,  l'affichage et la sauvegarde de la commande ayant permis la mise en place.
</div>

<div class="article">

<div class="section_title_small_blue"><h4>Sélectionnez une table</h4></div>

<table class="tableQueryCenter">
	<tr>
		<th>Nom</th>
		<th>Afficher</th>
	</tr>
<?php
	$nbRow = DevelopperModel::getTableNames($_SESSION['session']->currentConnection, $tableNames);
	
	if(isset($_GET['selected_table']))
		$selectedTable = $_GET['selected_table'];
	
	foreach ($tableNames as $row) {
		echo "<tr>";
		echo "<td>".$row['TABLE_NAME']."</td>\n";
		
		if(isset($selectedTable) && $selectedTable == $row['TABLE_NAME'])
		{
			?><td><img src="img/check.png" alt="check" /></td><?php
		}
		else
		{
			?><td><a href="#objects"><img src="img/find.png" alt="zoom" onClick="displayTables('<?php echo $row['TABLE_NAME'] ?>')" /></a></td><?php
		}
		
		
		echo"</tr>";
	}
?>
</table>

<br />

<?php
if(isset($selectedTable))
{
?>

<div class="section_title_small_green"><h4><?php echo $selectedTable ?></h4></div>

<div class="section_title_small_blue"><h4>Caractéristiques de stockage</h4></div>

<?php 

$nbRow = DevelopperModel::getTableInformations($_SESSION['session']->currentConnection, $tableInformations, $selectedTable, $columns);
displayVerticalResult($tableInformations, $columns);
?>

<div class="section_title_small_blue"><h4>Liste des index</h4></div>

<?php
	$nbRow = DevelopperModel::getTableIndexes($_SESSION['session']->currentConnection, $tableIndexes, $selectedTable, $columns2);
	displayResult($tableIndexes, $columns2);
?>

<div class="section_title_small_blue"><h4>Commande SQL</h4></div>

<?php
	$nbRow = DevelopperModel::getCreationQuery($_SESSION['session']->currentConnection, $tableQuery, 'TABLE', $selectedTable);
	$row = $tableQuery[0];
	if($_SESSION['session']->currentConnection->type == "ORACLE")
		$sql = $row['QUERY'];
	else if($_SESSION['session']->currentConnection->type == "MYSQL")
		$sql = $row['Create Table'];
?>


<div class="sql_code">
<pre class="sh_sql" id="code">
	<?php
	
	echo "\n".htmlentities($sql);
	?>
</pre>
</div>

<a href="view/main/DownloadView.php?name=Save.sql&text=<?php echo urlencode($sql) ?>" target="_blank"><input type="button" value="Télécharger" /></a>


<?php
}
?>

</div>

<script type="text/javascript" src="js/sql/shjs.js"></script>
<script type="text/javascript" src="js/sql/sh_sql.js"></script>
<script type="text/javascript">

	//JQuery main entry point
	 $(document).ready(function() {
		//Highlight query
		sh_highlightDocument();
	 });
</script>


